class: center, middle, inverse, title-slide .title[ # Testing Hypotheses ] .subtitle[ ## EDP 613 ] .author[ ### Week 9 ] --- <script> function resizeIframe(obj) { obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px'; } </script>
# A Note About The Slides Currently the equations do not show up properly in Firefox. Other browsers such as Chrome and Safari do work --- # A Note About Previous Items We're going to use some introduce some concepts from Chapter 7 here as well --- # Definitions The **margin of error** (**MoE**) is -- >- *Formally* : the range of values above and below a sample statistic within a confidence interval -- >- *In a nutshell* : how many percentage points your results will differ from the real population value -- >- NOT the same as a **confidence interval** -- <br> <br> (Statistical) **significance** is -- >- *Formally* : a measure of the probability of the null hypothesis being true compared to the acceptable level of uncertainty regarding the true answer -- >- *In a nutshell* : a result is probably not due to chance so it is likely real -- >- NOT the same as a **practical significance** --- # Interpretation <br> <br> <br> .pull-left[ <center> Example result:<br><br> A <b>95%</b> confidence interval with a<br><b>3% margin of error</b> </center> ] -- .pull-right[ <center> What it means:<br><br> Your statistic will be within<br><b>3 percentage points</b> of the real population value<br><b>95%</b> of the time </center> ] -- <br> <br> <br> <center> The <b>MoE</b> is a probability! </center> --- # Back to Hypothesis Testing <br> <br> <center>Recall</center> <br> <br> -- .pull-left[ The **null hypothesis `\(H_0\)`** states >- *Formally* : that a parameter is equal to a specific value >- *Informally* : nothing probably happened ] -- .pull-right[ The **alternative hypothesis `\(H_1\)`** states >- *Formally* : that a parameter differs from the value specified by the null hypothesis >- *Informally* : something probably happened ] --- # More about Hypothesis Testing Say a null hypothesis is `\(H_0\colon\mu=50\)`. Then three things can occur from a frequentist perspective -- - `\(H_1 < 50\)`: alternative hypothesis states that the parameter is *less* than the value of the null. -- >- You know to test for everything to the **left** of `\(H_1 = 50\)`. -- >- Called a **left-tailed test** -- <br> - `\(H_1 > 50\)`: alternative hypothesis states that the parameter is *more* than the value of the null. -- >- You know to test for everything to the **right** of `\(H_1 = 50\)`. -- >- Called a **right-tailed test** -- <br> - `\(H_1 \neq 50\)`: alternative hypothesis states that the parameter is *note* the value of the null. -- >- You know to test for everything to the **left** and **right** of `\(H_1 = 50\)`. -- >- Called a **two-tailed test** --- # `\(H_1 < H_0\)`: Left-Tailed Test <img src="Slides-Week-9_files/figure-html/unnamed-chunk-4-1.png" width="40%" style="display: block; margin: auto;" /> --- # `\(H_1 > H_0\)`: Right-Tailed Test <img src="Slides-Week-9_files/figure-html/unnamed-chunk-5-1.png" width="40%" style="display: block; margin: auto;" /> --- # `\(H_1 \neq H_0\)`: Two-Tailed Test <img src="Slides-Week-9_files/figure-html/unnamed-chunk-6-1.png" width="40%" style="display: block; margin: auto;" /> --- # Testing Methods <span class="brmedium"></span> -- .pull-left[ <center> <span class="brsmallmed"></span> <b><span style="color:#f4eebf;">Critical Value</span></b> (<b><i><span style="color:#f4eebf;">CV </span></i></b>) </center> ] -- .pull-right[ <center> <span class="brsmallmed"></span> <b><span style="color:#f4eebf;">`p`</b> - <b><span style="color:#f4eebf;">value</b> </center> ] --- # Critical Value - Uses a **test statistic** - determines how strong the disagreement between a sample mean and a null hypothesis -- - Idea: We should reject `\(H_0\)` if the value of the test statistic is unusual when we assume `\(H_0\)` to be true -- - Process -- - We choose a *CV* which forms a boundary between values that are considered unusual and values that are not -- - The region containing the unusual values is called the **critical region** -- - If the value of the test statistic is in the critical regions, we *reject* `\(H_0\)` --- # Transitioning (Again!) <span class="brmedium"><span> <center> Going from a `z`-distribution<br><br> <i>known population variance using `z`-scores</i> </center> -- <br> <br> <center>to</center> -- <br> <br> <center> a `t`-distribution<br><br> <i>known sample variance using `t`-tests</i> </center> --- # Note We have to assume that for a large enough sample size, the `\(t\)`-distribution will closely match, or estimate, the a `\(z\)`-distribution --- # Things to note - `\(t\)`-distribution table can be located in Appendix C -- - Assumptions -- - *Normality* - Samples are drawn from a population that fits a bell curve -- - *Independence* - Samples do not share values -- - *Random Sampling* - Samples are randomized -- - ***Homogeneity*** (for more than one sample) - Samples have a similar makeup --- # Steps to Solving 1. *Interpret the Question into Layman's Terms* 2. *Set Acceptable Threshold of Committing a Type I Error* 3. *State the Research Hypothesis* 4. *Calculate the Test Statistic* 5. *Determine the Critical Value* 6. *State the Decision Rule* 7. *Interpret the Results* --- # One-sample `\(t\)`-test - allows us to determine whether the mean of a sample data set is different than a known value -- - used when the population variance is not known -- - can be used when the sample size is small ~ typically `\(N<30\)`. --- # What the heck is a *degree of freedom*? -- 1. Forget statistics -- 2. Say you only own seven hats and want to wear a different one each day of the week. -- 3. Process - Day 1: Choose from 7 - Day 2: Choose from 6<br>     .<br>     . -- <ol class="nostyle"> <li class="nostyle"> <ul> <li class="nostyle">    .</li> <li class="nostyle">    .</li> <br> <li>Day 6: Choose from 2</li> <br> <li>Day 7: Choose from 1</li> </ul> </li> </ol> -- <ol start=4> You had 7 - 1 = <b>6</b> <i>days of hat freedom!</i> </ol> -- <center> That's essentially a degree of freedom (written <i>df </i>) </center> --- # One Sample Mean .center2[ .pull-left[ <center> <i>t</i>-distribution<br><br> </center> `$$t = \frac{\overline{Y}-\mu}{s/\sqrt{N}}$$` ] .pull-right[ <center> <i>with degrees of freedom<br><br> </center> `$$df = N-1$$` ] ] --- # Example .center2[ <table class="table" style="width: auto !important; margin-left: auto; margin-right: auto;"> <thead> <tr> <th style="text-align:center;background-color: #212121 !important;"> Region </th> <th style="text-align:center;background-color: #212121 !important;"> Median Household Income </th> <th style="text-align:center;background-color: #212121 !important;"> Median Male Salary </th> <th style="text-align:center;background-color: #212121 !important;"> Median Female Salary </th> <th style="text-align:center;background-color: #212121 !important;"> Population </th> <th style="text-align:center;background-color: #212121 !important;"> Households </th> </tr> </thead> <tbody> <tr> <td style="text-align:center;width: 10em; "> United States </td> <td style="text-align:center;width: 10em; "> $68,703 </td> <td style="text-align:center;width: 10em; "> $57,511 </td> <td style="text-align:center;width: 10em; "> $43,820 </td> <td style="text-align:center;width: 10em; "> 331,449,281 </td> <td style="text-align:center;"> 139,684,244 </td> </tr> <tr> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> West Virginia </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> $48,850 </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> $57,456 </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> $47,299 </td> <td style="text-align:center;width: 10em; background-color: #212121 !important;"> 1,793,716 </td> <td style="text-align:center;background-color: #212121 !important;"> 763,831 </td> </tr> </tbody> </table> ] -- Is the the median household income of West Virginia counties different than the national average? --- ## *Interpret the Question into Layman's Terms* From <b>Median Household Income</b>, we think WV (48,850 USD) is *practically lower* than the US (68,850 USD), but is it *significantly lower *? --- ## *Set Acceptable Threshold of Committing a Type I Error* `\(\alpha =0.5\)` --- ## *State the Research Hypothesis* <span class="brmedium"><span> .pull-left[ `$$H_0$$`<br><br> The <b>Median Household Income</b> of West Virginia counties is NOT significantly less than the national average ] -- .pull-right[ `$$H_1$$`<br><br> The <b>Median Household Income</b> of West Virginia counties is significantly less than the national average ] --- ## *Calculate the Test Statistic* (1/2) -- .pull-left[ <center>Population</center><br><br><br> $$\mu = \$68,703$$ ] -- .pull-right[ <center>Sample</center><br> `$$N=61$$` $$s = \$5075.28$$ $$\overline{Y} = \$45732.20$$ ] -- <br> <br> <center><i>df</i></center><br> `$$61-1 = 60$$` --- ## *Calculate the Test Statistic* (2/2) <span class="brmedium"><span> <br> `\begin{aligned} t &= \dfrac{45732.20-68703.00}{5075.28/\sqrt{61}} \\\\ &\approx -0.579 \end{aligned}` --- ## *Determine the Critical Value* In Appendix C, we see that for `\(df = 60\)` at `\(\alpha =0.05\)`, we have `\(t_{crit} = 1.671\)` --- ## *State the Decision Rule* Since `\(-0.579 < 1.671\)` we reject `\(H_0\)` --- ## *Interpret the Results* *The <b>Median Household Income</b> is significantly less than the national average!* --- # Two-sample Mean Used to compare one sample mean to another. - We use two different test: - Equal variances - Unequal variances (assumed) - **Homoscedasticity** – the assumption of equal variances. --- # Difference Between Two Independent Means -- >- Observations in each sample are not related >- Need to compare differences between the sample means -- <br> .pull-left[ <center>Estimated Standard Error</center><br> `$$S_{\overline{Y_1}-\overline{Y_1}} = \sqrt{\dfrac{(N_1-1)\cdot s_1^2+(N_2-1)\cdot s_2^2}{(N_1+N_2)-2}}\cdot\sqrt{\dfrac{N_1+N_2}{N_1\cdot N_2}}$$` ] -- .pull-right[ <center>difference between means <i>t</i>-statistic</center><br> `$$t = \dfrac{\overline{Y_1}-\overline{Y_2}}{S_{\overline{Y_1}-\overline{Y_1}}}$$` ] -- <br> <br> <center><i>df</i></center><br> `$$df = (N_1+N_2)-2$$` --- # Difference Between Proportions <br> .pull-left[ <center>Estimated Standard Error</center><br> `$$S_{p_1 - p_2} = \sqrt{\dfrac{p_1(1-p_1)}{N_1} + \dfrac{p_2(1-p_2)}{N_2}}$$` .pull-right[ <center>difference between means <i>z</i>-statistic</center><br> `$$z = \dfrac{p_1-p_2}{S_{p_1-p_2}}$$` ] --- # Example As part of the Pew Internet and American Life Project, researchers conducted two surveys in late 2009. The first survey asked a random sample of 800 U.S. teens about their use of social media and the Internet. A second survey posed similar questions to a random sample of 2253 U.S. adults. In these two studies, 73% of teens and 47% of adults said that they use social-networking sites. Use these results to construct and interpret a 95% confidence interval for the difference between the proportion of all U.S. teens and adults who use social-networking sites. --- ## *Interpret the Question into Layman's Terms* Is there a difference between the percent of teens and adults who use social networking sites? --- ## *Set Acceptable Threshold of Committing a Type I Error* `\(\alpha = 0.05\)` --- ## *State the Research Hypothesis* <span class="brmedium"><span> .pull-left[ `$$H_0$$`<br><br> There is no difference between the proportion of teens and adults who use social media ] -- .pull-right[ `$$H_1$$`<br><br> There is a difference between the proportion of teens and adults who use social media ] --- ## *Calculate the Test Statistic* `\begin{align} S_{p_1 - p_2} &= \sqrt{\dfrac{0.73(1-0.73)}{800} + \dfrac{0.47(1-0.47)}{2253}}\\\\ &\approx 0.0189 \end{align}` <br> <br> `\begin{align} z &= \dfrac{0.73-0.47}{0.0189}\\ &\approx 13.76 \end{align}` --- ## *State the Decision Rule* `\(z=13.76\)` is greater than `\(p\)` value implying that we reject `\(H_0\)` --- ## *Interpret the Results* We are 95% confident that in late 2009 more teens than adults in the United States engaged in social media --- ## That's it. Take a break before our R session!